﻿// This file is part of Code4Public (http://code4public.codeplex.com)
// Copyright 2011 Sina Iravanian - <sina@sinairv.com>
//
// This source file(s) may be redistributed, altered and customized
// by any means PROVIDING the authors name and all copyright
// notices remain intact.
// THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED. USE IT AT YOUR OWN RISK. THE AUTHOR ACCEPTS NO
// LIABILITY FOR ANY DATA DAMAGE/LOSS THAT THIS PRODUCT MAY CAUSE.
// ------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Code4Public.Settings;
using System.Diagnostics;
using Code4Public.GUI;

namespace Code4Public.ThemeDesigners
{
    public partial class ThemeDesigner : UserControl
    {
        private ThemePreviewBox m_themePreviewBox;
        public ThemeDesigner()
        {
            InitializeComponent();
        }

        private bool eventSuspended = false;

        private void SuspendEventRaising()
        {
            this.themeHeaderDesigner.SuspendEventRaising();
            this.themeBodyDesigner.SuspendEventRaising();
            this.themeLineNumbersDesigner.SuspendEventRaising();
            eventSuspended = true;
        }

        private void ResumeEventRaising()
        {
            this.themeHeaderDesigner.ResumeEventRaising();
            this.themeBodyDesigner.ResumeEventRaising();
            this.themeLineNumbersDesigner.ResumeEventRaising();
            eventSuspended = false;
        }

        public void SynchWithTheme(ThemePreviewBox themePreviewBox)
        {
            Debug.Assert(themePreviewBox != null);
            m_themePreviewBox = themePreviewBox;

            SuspendEventRaising();

            themeHeaderDesigner.HeaderBorder = m_themePreviewBox.Theme.HeaderBorder;
            themeHeaderDesigner.HeaderBackColor = m_themePreviewBox.Theme.HeaderBackColor;
            themeHeaderDesigner.HeaderFont = m_themePreviewBox.Theme.HeaderFont;
            themeHeaderDesigner.HeaderFontSize = m_themePreviewBox.Theme.HeaderFontSize;

            themeBodyDesigner.MainContentBorder = m_themePreviewBox.Theme.MainContentBorder;
            themeBodyDesigner.MainContentFontSize = m_themePreviewBox.Theme.MainContentFontSize;
            themeBodyDesigner.CodeContentBackColor = m_themePreviewBox.Theme.CodeContentBackColor;
            themeBodyDesigner.CodeContentFont = m_themePreviewBox.Theme.CodeContentFont;

            themeLineNumbersDesigner.LineNumbersBackColor = m_themePreviewBox.Theme.LineNumbersBackColor;
            themeLineNumbersDesigner.LineNumbersFont = m_themePreviewBox.Theme.LineNumbersFont;
            themeLineNumbersDesigner.LineNumbersSeperatorLineColor = m_themePreviewBox.Theme.LineNumbersSeperatorLineColor;
            themeLineNumbersDesigner.LineNumbersShowSeperatorLine = m_themePreviewBox.Theme.LineNumbersShowSeperatorLine;
            themeLineNumbersDesigner.LineNumbersShowStringAfter = m_themePreviewBox.Theme.LineNumbersShowStringAfter;
            themeLineNumbersDesigner.LineNumbersShowZeros = m_themePreviewBox.Theme.LineNumbersShowZeros;
            themeLineNumbersDesigner.LineNumbersSpacesAfter = m_themePreviewBox.Theme.LineNumbersSpacesAfter;
            themeLineNumbersDesigner.LineNumbersSpacesBefore = m_themePreviewBox.Theme.LineNumbersSpacesBefore;
            themeLineNumbersDesigner.LineNumbersStringAfter = m_themePreviewBox.Theme.LineNumbersStringAfter;

            ResumeEventRaising();
        }


        private void themeHeaderDesigner_HeaderThemeChanged(object sender, EventArgs e)
        {
            m_themePreviewBox.Theme.HeaderBorder = themeHeaderDesigner.HeaderBorder;
            m_themePreviewBox.Theme.HeaderBackColor = themeHeaderDesigner.HeaderBackColor;
            m_themePreviewBox.Theme.HeaderFont = themeHeaderDesigner.HeaderFont;
            m_themePreviewBox.Theme.HeaderFontSize = themeHeaderDesigner.HeaderFontSize;
            m_themePreviewBox.Refresh();
        }

        private void themeBodyDesigner_BodyThemeChanged(object sender, EventArgs e)
        {
            m_themePreviewBox.Theme.MainContentBorder = themeBodyDesigner.MainContentBorder;
            m_themePreviewBox.Theme.MainContentFontSize = themeBodyDesigner.MainContentFontSize;
            m_themePreviewBox.Theme.CodeContentBackColor = themeBodyDesigner.CodeContentBackColor;
            m_themePreviewBox.Theme.CodeContentFont = themeBodyDesigner.CodeContentFont;
            m_themePreviewBox.Refresh();
        }

        private void themeLineNumbersDesigner_LineNumbersThemeChanged(object sender, EventArgs e)
        {
            m_themePreviewBox.Theme.LineNumbersBackColor = themeLineNumbersDesigner.LineNumbersBackColor;
            m_themePreviewBox.Theme.LineNumbersFont = themeLineNumbersDesigner.LineNumbersFont;
            m_themePreviewBox.Theme.LineNumbersSeperatorLineColor = themeLineNumbersDesigner.LineNumbersSeperatorLineColor;
            m_themePreviewBox.Theme.LineNumbersShowSeperatorLine = themeLineNumbersDesigner.LineNumbersShowSeperatorLine;
            m_themePreviewBox.Theme.LineNumbersShowStringAfter = themeLineNumbersDesigner.LineNumbersShowStringAfter;
            m_themePreviewBox.Theme.LineNumbersShowZeros = themeLineNumbersDesigner.LineNumbersShowZeros;
            m_themePreviewBox.Theme.LineNumbersSpacesAfter = themeLineNumbersDesigner.LineNumbersSpacesAfter;
            m_themePreviewBox.Theme.LineNumbersSpacesBefore = themeLineNumbersDesigner.LineNumbersSpacesBefore; 
            m_themePreviewBox.Theme.LineNumbersStringAfter = themeLineNumbersDesigner.LineNumbersStringAfter;
            m_themePreviewBox.Refresh();
        }
    }
}
